﻿
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div id="appProject" style="margin:2px;padding:2px;">
    <el-form inline label-position="right" label-width="70px" class="query-form">
        <el-form-item label="项目名称">
            <el-input placeholder="请输入项目名称" style="width:150px;" v-model="projectName"></el-input>
        </el-form-item>
        @*<el-form-item label="配置方式">
            <el-select v-model="storageType">
                <el-option label="全部" value="0"></el-option>
                <el-option label="共享目录" value="1"></el-option>
                <el-option label="Mysql" value="2"></el-option>
            </el-select>
        </el-form-item>*@
        <el-form-item label="状态">
            <el-select v-model="enabled">
                <el-option label="全部" value="null"></el-option>
                <el-option label="启用" value="true"></el-option>
                <el-option label="禁用" value="false"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="success" size="small" @@click="projectEdit(null)" v-show="pageButtons.includes('addproject')">新增</el-button>
            <el-button type="primary" size="small" @@click="handleSearch">查询</el-button>
        </el-form-item>
    </el-form>
    <el-table :data="tableData" stripe border style="width:100%" size="mini">
        <el-table-column type="index" width="50" align="center"></el-table-column>
        <el-table-column prop="code" label="项目编码" width="180"></el-table-column>
        <el-table-column prop="projectName" label="项目名称" width="180"></el-table-column>
        @*<el-table-column prop="storageType" label="配置方式" width="180">
            <template slot-scope="scope">
                <span v-if="scope.row.storageType==1">共享目录</span>
                <span v-if="scope.row.storageType==2">Mysql</span>
            </template>
        </el-table-column>*@
        <el-table-column label="状态" width="100" align="center">
            <template slot-scope="scope">
                <el-button type="success" round size="mini" v-if="scope.row.enabled==true">{{scope.row.enabled === false ? '禁用' : '启用'}}</el-button>
                <el-button type="danger" round size="mini" v-if="scope.row.enabled==false">{{scope.row.enabled === false ? '禁用' : '启用'}}</el-button>
            </template>
        </el-table-column>
        <el-table-column prop="orderIndex" label="排序" width="100" align="center"> </el-table-column>
        <el-table-column prop="remark" label="备注" width="300"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="200" align="center">
        </el-table-column>
        <el-table-column prop="createByName" label="创建人" width="180"></el-table-column>
        <el-table-column prop="updateTime" label="修改时间" width="200" align="center">
        </el-table-column>
        <el-table-column prop="updateByName" label="修改人" width="180"></el-table-column>
        <el-table-column fixed="right" label="操作" width="450" align="center">
            <template slot-scope="scope">
                <el-button type="primary" size="mini" @@click="projectEdit(scope.row)" v-show="pageButtons.includes('editproject')">修改</el-button>
                <el-button :type="scope.row.enabled === true?'danger':'success'" @@click="SetEnabled(scope.row)" size="mini" v-show="pageButtons.includes('setenabledproject')">
                    <span>{{scope.row.enabled === true ? '禁用' : '启用'}}</span>
                </el-button>
                <el-button type="warning" size="mini" @@click="configSet(scope.row )" v-show="pageButtons.includes('settingconfigproject')">设置配置</el-button>
                <el-button type="info" size="mini" @@click="historySettings(scope.row )" v-show="pageButtons.includes('hitoryconfigproject')">历史配置</el-button>
                <el-button size="mini" @@click="projectDetail(scope.row )" v-show="pageButtons.includes('viewproject')">查看</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination @@size-change="handleSizeChange"
                   @@current-change="handleCurrentChange"
                   :current-page="currentPage"
                   :page-sizes="[10, 20, 50, 100]"
                   :page-size="10"
                   layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
</div>

<style>
    .el-table .warning-row {
        background: oldlace;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }

    .el-table td {
        /*padding: 5px 0 !important;*/
    }
</style>

<script>
    function refreshFromChild() {
        vueProject.GetProjectList();
    }

    var vueProject = new Vue({
        el: '#appProject',
        data() {
            return {
                pageButtons: [],

                projectName: '',
                enableStatus: 0,
                storageType: '0',
                enabled:'null',
                pageSize: 10,
                currentPage: 1,
                total: 0,
                tableData: []
            }
        },
        created(){
            var _this = this;
            this.GetProjectList();

            _this.$getMenuButtons();
        },
        methods: {
            configSet: function (row) {
                let id = row.id;
                if (row.storageType == 1) {
                    this.$addTab(id, "项目配置", "../project/ConfigSettings?projectId=" + id);
                } else if (row.storageType == 2) {
                    this.$addTab(id, "项目配置", "../project/ConfigDbSettings?projectId=" + id);
                }
            },
            historySettings: function (row) {
                this.$addTab(row.id, "历史配置", "../project/History?projectId=" + row.id+"&envId="+ 0);
            },
            projectEdit(row) {
                var id = 0;
                if (row) id = row.id;
                this.$addTab(id, id == 0 ? "新增项目" : "修改项目", "../project/edit?id=" + id);
            },
             projectDetail(row ) {
                 this.$addTab(row.id, "项目详情", "../project/detail?id=" + row.id);
            },
            tableRowClassName({ row, rowIndex }) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            handleSearch() {
                this.GetProjectList();
            },
            handleClick(row) {
                console.log(row);
            },
             GetProjectList() {
                  var _this = this;
                 _this.$post("@Url.Action("GetProjectList", "Project")", {
                     PageIndex: _this.currentPage,
                     PageSize: _this.pageSize,
                     ProjectName: _this.projectName,
                     enabled: _this.enabled == 'null' ? null : _this.enabled =="true"?true:false,
                     storageType: parseInt(_this.storageType)
                 }).then((response) => {
                     _this.tableData = response.items;
                        _this.total = response.totalCount;
                  }).catch((error) => {
                  });
            },
            SetEnabled(row) {
                  var _this = this;
                  axios.post("@Url.Action("SetEnabled", "Project")", {
                      Id: row.id,
                      Enabled: !(row.enabled)
                  }).then((res) => {
                      _this.$success(res.message, function () {
                          if(res.success)
                             _this.GetProjectList();
                      });


                  }).catch((error) => {
                  });
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.GetProjectList();
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.GetProjectList();
            }
        }
    });
</script>
